package lamer;

import irio.gamer.GamerImage;
import irio.gamer.gamer;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.io.IOException;

import javax.swing.JPanel;
import javax.swing.JProgressBar;

public class ImageFrame extends JPanel {

    public static GamerImage LImagePanel = new GamerImage(LSettings.outputFile + ".bmp", "Current likelihood image");
    public static GamerImage OrgImagePanel = new GamerImage(LSettings.dataFile + ".bmp","Data");

	public JProgressBar progressBar = new JProgressBar();

	
	static public void Fits2Bmp(String input) {
		//gutil create_rgb [source_r] [source_g] [source_b] [target bmp] [weight r] [weight g] [weight b] [power] [cutoff]
		String ifile = input  + ".fits";
		Process p;
		try {
			p = Runtime.getRuntime().exec(
					"bin/gutil create_rgb  " + ifile + " " + ifile + " " + ifile + " " +input + ".bmp " +  "1 1 1 0.65 0.9");
			gamer.waitforProcess(p);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	static public void reload() {
		LImagePanel.loadImage();
		OrgImagePanel.loadImage();
	}
	
	static public void Normalize(String filename) {
		
		String ifile = filename  + ".fits";
		Process p;
		try {
			p = Runtime.getRuntime().exec(
					"bin/gutil normalize " +ifile + " " + ifile + " 1.0");
			gamer.waitforProcess(p);
			p = Runtime.getRuntime().exec(
					"bin/gutil pow " +ifile + " " + ifile + " 2.0");
			gamer.waitforProcess(p);

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	
	public ImageFrame() {
		setLayout(new GridLayout(2,1));
		add(LImagePanel);
		add(OrgImagePanel);
        
 //       preview.Update();
  //      setSize(600,600);

//        setSize(512,600);
//        gamerImagePanel.setSize( 400, 300 );
	}
	
	
}
